package Q3;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

    public static int n;
    public static int m;
    public static int[][] arr;
    public static int ret;
    public static int[] dx = {0, 0, 1, -1};
    public static int[] dy = {1, -1, 0, 0};

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        n = scanner.nextInt();
        m = scanner.nextInt();
        arr = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = scanner.nextInt();
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                Queue<int[]> queue = new LinkedList<>();
                queue.offer(new int[]{i, j});
                bfs(new boolean[n][m], queue);
            }
        }

        System.out.println(ret);
    }

    public static void bfs(boolean[][] flag, Queue<int[]> queue) {
        int step = 0;

        while (!queue.isEmpty()) {
            int size = queue.size();
            while (size > 0) {
                size--;
                int[] arr1 = queue.poll();
                int x = arr1[0];
                int y = arr1[1];
                step++;
                flag[x][y] = true;
                for (int i = 0; i < 4; i++) {
                    int xx = x + dx[i];
                    int yy = y + dy[i];
                    if (xx >= 0 && xx < n && yy >= 0 && yy < m && !flag[xx][yy] && arr[x][y] > arr[xx][yy]) {
                        queue.offer(new int[]{xx, yy});
                        flag[xx][yy] = true;
                    }
                }
            }
        }

        ret = Math.max(ret, step);
    }
}
